<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    {% load static %}
    <link rel="stylesheet" href="{% static '/css/bootstrap.min.css' %}">
    <script src="{% static '/js/jquery-3.2.1.min.js' %}"></script>
    <script src="{% static '/js/bootstrap.min.js' %}"></script>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script>
        function checkclientid() {
            let clientid = $("#clientid").val();
            let sendData = {
                "clientid":clientid,
                "csrfmiddlewaretoken":"{{ csrf_token }}"
            };
            if (!clientid){
                $("#checkname").attr("class", "form-group has-error");
                return false;
            }else {
                $.ajax({
                    url:"/checkclientid/",
                    data:sendData,
                    type:"post",
                    success:function (data) {
                        let result = data["resule"];
                        if (result === "可用"){
                            $("#checkname").attr("class", "form-group has-success");
                            return true;
                        }else {
                            $("#checkname").attr("class", "form-group has-error");
                            return false;
                        }
                    }
                })
            }
        }
        function checkinput(theId) {
            let flag1 = $("#check"+theId).is(':checked');
            let flag2 = !!$("#ingrnum"+theId).val();
            if (!((flag1 && flag2) || (!flag1 && !flag2))) {
                $("#tr" + theId).attr("class", "has-error");
                return false;
            } else {
                $("#tr" + theId).attr("class", "has-success");
                return true;
            }
        }
        function checkall() {
            let flag1 = $(".has-error").length ==0;
            let flag2 = !!$("input.myCheck[name=table]:checked").val();
            alert(flag1+"text"+flag2+"测试信息");
            return flag1&&flag2
        }
    </script>
</head>
<body>
<div class="container">
    <div class="row">
        <div class="col-md-8 col-md-offset-4">
            <h3>点餐</h3>
            <a href="/waiter/">返回主页</a>
        </div>
    </div>
</div>
<div class="container">
    <div class="row">
        <div class="col-md-9 col-md-offset-2">
            <form method="post" action="" onsubmit="return checkall()" class="form-horizontal">
                {% csrf_token %}
                <table class="table-striped">
                    <tr>
                        <td>选择</td>
                        <td>菜品名称</td>
                        <td>菜品价格</td>
                        <td>菜品数量</td>
                    </tr>
                    {% for dish in disheslist %}
                        <tr id="tr{{ dish.id }}" class="">
                            <td>
                                <div class="checkbox">
                                    <label>
                                        <input type="checkbox" id="check{{ dish.id }}" onblur="checkinput({{ dish.id }})" name="dishes" value="{{ dish.id }}">
                                    </label>
                                </div>
                            </td>
                            <td>{{ dish.name }}</td>
                            <td>{{ dish.price }}</td>
                            <td>
                                <div class="input-group">
                                    <span class="input-group-addon"><label for="number{{ dish.id }}">数量</label></span>
                                    <span><input type="number" onblur="checkinput({{ dish.id }})" id="ingrnum{{ dish.id }}" name="number{{ dish.id }}"></span>
                                </div>
                            </td>
                        </tr>
                    {% endfor %}
                </table>
                餐桌号：
                <label>
                    {% for pretable in pretablelist %}
                            <input type="radio" class="myCheck" name="table" value="{{ pretable.tableid.id }}"> {{ pretable.tableid.id }}
                    {% endfor %}
                </label>
                <div class="input-group col-md-1 col-md-offset-1">
                    <button class="button">提交</button><span>{{ msg }}</span>
                </div>
            </form>
        </div>
    </div>
</div>
</body>
</html>